package com.cloud.lawcase.interfaces;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.cloud.lawcase.common.config.FeignConfiguration;
import feign.hystrix.FallbackFactory;


@FeignClient(value = "SYSTEM",  configuration = FeignConfiguration.class, fallbackFactory = FeignClientSystemFallbackFactory.class)
public interface FeignClientSystem {
	@RequestMapping(value = "system/interface/sysconfig/item", method = RequestMethod.GET)
	String getConfigValueByKey( @RequestParam("configKey") String configKey);
}
@Component
class FeignClientSystemFallbackFactory implements FallbackFactory<FeignClientSystem> {
	private static final Logger LOGGER = LoggerFactory.getLogger(FeignClientSystemFallbackFactory.class);
	@Override
	public FeignClientSystem create(final Throwable cause) {
		return new FeignClientSystem() {
			@Override
			public String getConfigValueByKey(String configKey) {
				if (FeignClientSystemFallbackFactory.LOGGER.isDebugEnabled()) {
					FeignClientSystemFallbackFactory.LOGGER.debug("getConfigValueByKey fallback; reason was:" + cause);
				}
				return "";
			}
		};
	}

}
